<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml"
      xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>应收台账</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
          name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <link rel="stylesheet" href="/dist/plugins/select2/select2.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=39cd89cd">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <style>
        .table > tbody > tr > td {
            line-height: 24px;
            max-height: 24px;
            overflow: hidden;
        }

        .content {
            padding: 2px;
        }

        span.lineOne {
            line-height: 28px;
            height: 28px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            /*-webkit-line-clamp: 1;*/
        }

        .div-td-content-more {
            position: absolute;
            height: auto;
            z-index: 999;
            line-height: 20px;
            background-color: #d3e8fd;
            padding: 8px 6px;
            border: 1px solid #e8e8ea;
            display: none;
        }

        .divCheck {
            height: 100%;
            margin-left: 5px;
            line-height: 10px;
        }

        .divCheck input {
            float: left;
            margin-top: -3px;
            margin-right: 5px;
        }

        .div-td-content-more i {
            width: 15px;
            height: 12px;
            background: url("/dist/img/more-icon.png");
            position: absolute;
            left: 50px;
            top: -12px;
        }

        .red{
            color: #fff;
            background: red;
        }
        .blue{
            color:#000;
            background-color: orange;
        }

        .ygColor {

        }

        .redFont{
            color: red;
        }
        .orangeFont{
            color: orange;
        }

        .tryStyle {
            width: 30px;
            height: 14px;
            line-height: 14px;
            font-size: 12px;
            /* top: 0; */
            /*right: 0;*/
            position: absolute;
            border-radius: 5px;
            margin-top: 7px;
            background: red;
            color: #fff;
            margin-right: -2px;
            transform: scale(0.8);
        }

        .table>thead>tr>th{
            border-bottom: 1px solid #cbcbcd;
            background: #F8F8F8;
        }
        .btn-blue {
            border: none;
            background: #2a8cec;
            color: #fff;
            width: 14%;
        }
        .btn-blue.focus, .btn-blue:focus, .btn-blue:hover {
            color: #fff;
            text-decoration: none;
        }
    </style>
</head>
<body>
<section class="content" id="app">
    <div class="div-td-content-more"><i></i></div>
    <div style="display:flex;height: 30px;margin-bottom: 10px;margin-top:8px;">
        <input type="text" placeholder="关键字" style="flex: 1;height:30px;outline: none;margin-left: 6px;" v-model="searchParams.customerKey" id="txtParent">
        <button type="button" class="btn btn-blue" style="margin-left: 10px;float: left;" @click="getList">查询</button>
        <div class="pull-left divCheck">
            <label style="margin-top: 10px"><input type="checkbox" id="cbCheck" v-model="haveSettle" @change="getList"
                          >显示已结清
            </label>
        </div>
    </div>
    <div class="box-body no-padding iframeH2" style="overflow: auto;" id="scrollDiv">
        <table class="table table-bordered text-center" style="table-layout: auto">
            <thead>
            <tr>

                <th style="width: 15%">公司</th>
                <th style="width: 15%">客户</th>
                <th style="width:19%">到期日期</th>
                <!--<th style="width: 100px">品牌</th>-->
                <!--<th style="width: 61px">设备类型</th>-->
                <th style="width: 17%">到期金额</th>
                <th style="width: 17%">逾期罚息</th>
                <th style="width: 17%">合计</th>
                <!--<th style="width: 39px">结清</th>-->
                <!--<th style="width: 39px">逾期</th>-->

                <!--<th style="width: 61px">大区经理</th>-->
                <!--<th style="width: 61px">债权经理</th>-->
                <!--<th style="width: 61px">数据专员</th>-->
            </tr>
            </thead>
            <tbody id="tbList">
            <tr v-for="(item,i) in tablesMergeCell(list)" >
                <!--<td>{{i+1}}</td>-->
                <td :rowspan="item.sellerspan" :class="{hidden: item.sellerdis}"><span class="lineOne">{{item.seller}}</span></td>
                <td  style="background-color: white;" :rowspan="item.buyerspan" :class="{hidden: item.buyerdis}"><span class="lineOne" style="color:#2a8cec;cursor: pointer;" @click="goDetail('look',item)">{{item.buyer}}</span>
                </td>
                <td>
                    <span v-if="item.haveSettle == '1'">
                        已结清
                    </span>
                    <template v-else>
                        <span class="lineOne" style="text-align: left;">{{item.repaymentDate? item.repaymentDate.substring(5): '未到期'}}
                        <span style="text-align: center" v-if="(Number(item.overduePenalty)>0||Number(item.remainingArrears)>0)&&compareFiveDate(item.repaymentDate)<0" class="tryStyle">逾期</span>
                        <span v-else-if="Number(item.total)>0 && Number(item.overduePenalty)==0" class="tryStyle"
                              style="background: #2a8cec;color: #fff;text-align: center">到期</span>
                        </span>
                    </template>
                </td>
                <td :style="item.remainingArrears?'text-align: right':'text-align: right'"
                    v-if="(item.overduePenalty && Number(item.overduePenalty)>0)||(item.remainingArrears && Number(item.remainingArrears)>0)">
                    <span class="lineOne">{{item.remainingArrears ?fmoney(item.remainingArrears):'-'}}</span>
                </td>
                <td v-else :style="item.total?'text-align: right':'text-align: right'">
                    <span>{{item.total ? fmoney(item.total) :'-'}}</span>
                </td>
                <td :style="item.overduePenalty ? 'text-align: right':'text-align: right'">
                    <span class="lineOne"
                          v-if="(Number(item.overduePenalty)>0||Number(item.remainingArrears)>0)&&compareFiveDate(item.repaymentDate)<0"> {{item.overduePenalty? fmoney(item.overduePenalty):'未知'}}</span>

                    <span class="lineOne" v-else> {{item.overduePenalty? fmoney(item.overduePenalty):'-'}}</span>
                </td>
                <td :style="item.newMoney? 'text-align: right':'text-align: right'" :rowspan="item.buyerspan"
                    :class="{hidden: item.buyerdis}">
                    {{item.newMoney? fmoney(item.newMoney):'-'}}
                </td>
            </tr>
            </tbody>
        </table>
        <div class="oa-pager text-center" style="margin-top: 5px;">
            共
            <span id="allCount"> 0 </span>条记录&nbsp;&nbsp;&nbsp;
            <span id="nowPage"> 1 </span>/<span id="allPage">1</span>&nbsp;&nbsp;&nbsp;
            <span class="oa-pager-button" id="first">首页</span>
            <span class="oa-pager-button" id="prev">上一页</span>
            <span class="oa-pager-button" id="next">下一页</span>
            <span class="oa-pager-button" id="last">尾页</span>
        </div>
    </div>
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oaApp.js"></script>
<!--插件JS-->
<script src="/dist/plugins/scroll/myScroll.js"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script src="/dist/plugins/select2/select2.full.min.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script>
    $.ajaxSetup({
        global: true,
        type: "POST",
        cache: false,
        dataType: "json",
        contentType: 'application/json;charset=utf-8',
        beforeSend: function () {
        },
        complete: function () {

        },
        error: function (e) {
            alert('error' + e.responseText);
        }
    });
    $.extend($.wyui, {
        page: {
            urlParams: null,
            queryParams: {
                requestPage: 1,
                pageSize: 30
            },
            dataUrl: '',
            getByPage_callback: null,
            createQueryParams: function () {
            },
            getByPage: function (type) {
                if (type == "scroll") {
                    $.wyui.page.queryParams.requestPage++;
                }
                $.ajax({
                    url: $.wyui.page.dataUrl,
                    data: JSON.stringify($.wyui.page.queryParams),
                    beforeSend: function () {

                    },
                    complete: function () {
                    },
                    success: function (r) {
                        $("#allCount").html(r.data.sendData.pager.recordCount);
                        $("#nowPage").html($.wyui.page.queryParams.requestPage);
                        if (r.data.sendData.pager.pageCount == 0) {
                            r.data.sendData.pager.pageCount = 1;
                        }
                        $("#allPage").html(r.data.sendData.pager.pageCount);
                        if (type == "scroll") {
                            $.wyui.page.getByPage_scroll_callback(r.data.sendData.records);
                        } else {
                            $.wyui.page.getByPage_callback(r.data.sendData.records);
                            if ($.wyui.page.getByPage_callback_new) {
                                $.wyui.page.getByPage_callback_new(r.data.sendData);
                            }
                        }

                    }
                });
            }
        },
        postMethod: function (url, data, callback, sync, id) {
            if (!id) {
                id = "#app"
            }
            $.ajax({
                url: server.ip + url,
                async: sync ? false : true,
                data: JSON.stringify(data),
                beforeSend: function () {

                },
                complete: function () {
                    setTimeout(function () {
                    }, 1000);

                },
                success: function (r) {
                    if (!r.e.code) {
                        callback(r.data.sendData);
                    } else {
                        alert(r.e.desc);
                    }
                },
                error: function (e) {
                    alert(url + e.responseText);
                }
            });
        },
    });
</script>
<script>
    $(function () {
        $("body").on("click", ".lineOne,.lineTwo", function (e) {
            if ($(".div-td-content-more").is(":hidden")) {
                var text = $(this).text();
                if (text != "") {
                    text = "<i></i>" + text;
                    $(".div-td-content-more").html(text).css({
                        "width": $(this).outerWidth() + 12 + "px",
                        "left": $(this).offset().left - 6,
                        "top": ($(this).offset().top + $(this).outerHeight()) + "px"
                    }).show();
                    e.stopPropagation();
                }
            } else {
                $(".div-td-content-more").hide();
            }
        });
        $("body").on("click", ".div-td-content-more", function (e) {
            e.stopPropagation();
        });
        $("body").on("click", function () {
            $(".div-td-content-more").hide();
        });
    });
</script>
<script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            rightOp: [],//权限列表
            haveSettle: false,
            list: [],
            pageType: getUrlParamObj().pageType,
            searchParams: {
                auditFlag: 1,
                haveDelivery: 1,
                haveSettle: 0,
                userId: getUrlParamObj().userId,
                customerKeyId: '',
                createUserId: '',
                customerKey: '',
                createUserName: '',
                // requestPage: getUrlParamObj().requestPage ? getUrlParamObj().requestPage : 1,
                // pageSize: getUrlParamObj().pageSize ? getUrlParamObj().pageSize : 20,
            },
        },
        methods: {
            //合并单元格
            tablesMergeCell: function (list) {
                if (list != undefined && list && list.length > 0) {
                    for (field in list[0]) {
                        var k = 0;
                        while (k < list.length) {
                            list[k][field + 'span'] = 1;
                            list[k][field + 'dis'] = false;
                            for (var i = k + 1; i <= list.length - 1; i++) {
                                if (list[k][field] == list[i][field] && list[k][field] != '') {
                                    list[k][field + 'span']++;
                                    list[k][field + 'dis'] = false;
                                    list[i][field + 'span'] = 1;
                                    list[i][field + 'dis'] = true;
                                } else {
                                    break;
                                }
                            }
                            k = i;
                        }
                    }
                }
                return list;
            },
            getList: function () {
                if (this.haveSettle) {
                    this.searchParams.haveSettle = ""
                } else {
                    this.searchParams.haveSettle = 0
                }
                var that = this;
                var dialog = {
                    dialog: 'show'
                }
                prompt(JSON.stringify(dialog))
                $.wyui.page.dataUrl = server.ip + "/receivable/selectContractAccountListApp.json"
                $.wyui.page.queryParams.requestPage = 1;
                $.extend($.wyui.page.queryParams, that.searchParams);
                $.wyui.page.getByPage();
            },
            isShowBtn: function (eName) {
                if ($.inArray(eName, this.rightOp) > -1) {
                    return true;
                } else {
                    return false;
                }
            },
            getNowDate: function () {
                var now = new Date();
                var year = now.getFullYear();
                var month = (now.getMonth() + 1).toString();
                var day = (now.getDate()).toString();
                var hour = (now.getHours()).toString();
                var minute = (now.getMinutes()).toString();
                var second = (now.getSeconds()).toString();
                if (month.length == 1) {
                    month = "0" + month;
                }
                if (day.length == 1) {
                    day = "0" + day;
                }
                if (hour.length == 1) {
                    hour = "0" + hour;
                }
                if (minute.length == 1) {
                    minute = "0" + minute;
                }
                if (second.length == 1) {
                    second = "0" + second;
                }
                var dateTime = year + "-" + month + "-" + day;
                return dateTime;
            },
            compareFiveDate: function (ydDate) {
                var aDate = new Date(this.getNowDate()); // 通过日期字符串，初始化第一个日期对象
                var bDate = new Date(ydDate); // 同上，初始化第二个日期对象
                var aDay = 24 * 60 * 60 * 1000; // 完整一天有24小时，将小时换算成毫秒时间戳
                var diffDay = (bDate - aDate) / aDay; // 计算间隔天数（注意日期隐式转换）
                console.log(diffDay); // 2，23日-25日间隔2天
                return diffDay;
            },
            fmoney: function (s, n) {
                n = n > 0 && n <= 20 ? n : 2;
                s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
                var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1],
                    t = "";
                for (i = 0; i < l.length; i++) {
                    t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
                }
                return t.split("").reverse().join("") + "." + r;
            },
            goDetail: function (type, item) {
                var obj = {
                    type: 'goDetail',
                    url: '/apply/accountReceivable/detailApp.html?id=' + item.id + "&pageType=look&userId=" + getUrlParamObj().userId,
                    id: item.id,
                    name: "应收详情",
                    screenType: '0',
                }
                prompt(JSON.stringify(obj))
            },
            // getByPage() {
            //     var dialog = {
            //         dialog: 'show'
            //     }
            //     prompt(JSON.stringify(dialog))
            //     var that = this;
            //     $.ajax({
            //         url: server.ip + "/contractMain/selectContractAccountList.json",
            //         contentType: 'application/json;charset=utf-8',
            //         type: "POST",
            //         data: JSON.stringify(that.searchParams),
            //         success: function (r) {
            //             var dialog = {
            //                 dialog: 'hidden'
            //             }
            //             prompt(JSON.stringify(dialog))
            //             var res = JSON.parse(r)
            //             that.sendData = res.data.sendData;
            //             that.list = that.sendData.records
            //         },
            //         error: function (e) {
            //             alert(e.responseText)
            //         }
            //     });
            // }
        },
        mounted: function () {
            $(".oa-pager-button").click(function () {
                var allPage = parseInt($("#allPage").html());
                switch (this.id) {
                    case "first":
                        $.wyui.page.queryParams.requestPage = 1;
                        break;
                    case "next":
                        $.wyui.page.queryParams.requestPage++;
                        break;
                    case "prev":
                        $.wyui.page.queryParams.requestPage--;
                        break;
                    case "last":
                        $.wyui.page.queryParams.requestPage = allPage;
                        break;
                    default:
                        break;
                }
                if ($.wyui.page.queryParams.requestPage == 0) {
                    $.wyui.page.queryParams.requestPage = 1;
                } else if ($.wyui.page.queryParams.requestPage > allPage) {
                    $.wyui.page.queryParams.requestPage = allPage;
                }
                $.wyui.page.getByPage();
            });
            this.getList()
            //查询用户有哪些权限
            // var that = this;
            // var data = {userId: getUrlParamObj().userId}
            // $.ajax({
            //     url: server.ip + urlConfig.system.rightOp.getRightOpByUserId,
            //     contentType: 'application/json;charset=utf-8',
            //     type: "POST",
            //     data: JSON.stringify(data),
            //     success: function (r) {
            //         var res = JSON.parse(r)
            //         that.sendData = res.data.sendData;
            //         var rightOp = that.sendData
            //         for (var i = 0; i < rightOp.length; i++) {
            //             that.rightOp.push(rightOp[i].eName);
            //         }
            //         console.log("权限列表如下：")
            //         console.log(that.rightOp);
            //     },
            //     error: function (e) {
            //         alert(e.responseText)
            //     }
            // });
        }
    });

    $(function () {
        $("#regionManagerName").autoComplete({
            url: server.ip + urlConfig.system.user.getTop10ByNameUser,
            render: function (users, panel) {
                for (var i = 0; i < users.length; i++) {
                    $("<li></li>").data("autoComplete",
                        users[i]).html("<a>" + users[i].name + "&nbsp;&nbsp;&nbsp;" +
                        "(" + "&nbsp;" + users[i].companyName + "-" + users[i].departName + "-" + users[i].roleName + "&nbsp;" + ") " + "</a>")
                        .appendTo(panel);
                }
            },
            selected: function (user) {
                app.searchParams.regionManagerKeyId = user.id;
                app.searchParams.createUserName = user.name;
                return false;
            },
            height: 210,
            width: 220
        });

    });
    $.wyui.page.dataUrl = server.ip + "/receivable/selectContractAccountListApp.json"
    $.extend($.wyui.page.queryParams, app.searchParams);
    // $.wyui.page.getByPage()
    $.wyui.page.getByPage_callback = function (records) {
        console.log(records)
        var dialog = {
            dialog: 'hidden'
        }
        prompt(JSON.stringify(dialog))
        var list1 = [];
        for (var i = 0; i < records.length; i++) {
            if (records[i].haveDsdf == '0' && (records[i].type != '2' && records[i].type != '4')) {
                list1.push(records[i])
            }
            if (records[i].haveDsdf == '1' && (records[i].type != '10' && records[i].type != '12')) {
                list1.push(records[i])
            }
        }
        for(var a=0;a<list1.length;a++){
            var item=list1[a];
            if(item.overduePenalty && Number(item.overduePenalty)>0||item.remainingArrears && Number(item.remainingArrears)>0){
                item.count=Number(item.remainingArrears)+Number(item.overduePenalty)
            }else{
                item.count=Number(item.total)+Number(item.overduePenalty)
            }
        }

        for(var a=0;a<list1.length;a++){
            var newMoney=list1[a].count;
            for(var b=0;b<list1.length;b++){
                if(list1[a].buyer==list1[b].buyer&&list1[a].id==list1[b].id&&a!=b){
                    newMoney+=Number(list1[b].count)
                }
            }
            list1[a].newMoney=newMoney;
        }
        app.list = list1;
        document.getElementById("scrollDiv").scrollTop = 0;
    };
    $.wyui.page.getByPage_scroll_callback = function (list) {
        if (list.length < 30) {
            isLoad = false;
        } else {
            for (var i = 0; i < list.length; i++) {
                app.list.push(list[i]);
            }
            isLoad = true;
        }
    }
</script>
<script>
    /************************滚动加载******************************/
    var divscroll = document.getElementById('scrollDiv');

    function divScroll() {
        var wholeHeight = divscroll.scrollHeight;
        var scrollTop = divscroll.scrollTop;
        var divHeight = divscroll.clientHeight;
        console.log(scrollTop + divHeight, wholeHeight)
        if (scrollTop + divHeight >= wholeHeight - 2) {
//            alert('滚动到底部了！');
            if (isLoad) {
                isLoad = false;
                setTimeout($.wyui.page.getByPage("scroll"), 1000);

            }

            //这里写动态加载的逻辑，比如Ajax请求后端返回下一个页面的内容
        }

    }

    divscroll.onscroll = divScroll;
</script>
</body>
</html>